home *** CD-ROM | disk | FTP | other *** search
/ Apple Developer Connection Student Program / ADC Tools Sampler CD Disk 3 1999.iso / Metrowerks CodeWarrior / Java Support / Java_Source / IFC_112 / netscape / application / CommandEvent.java < prev    next >
Encoding:
Text File  |  1999-05-28  |  2.4 KB  |  93 lines  |  [TEXT/CWIE]

  1. // CommandEvent.java
  2. // By Ned Etcode
  3. // Copyright 1996, 1997 Netscape Communications Corp.  All rights reserved.
  4.  
  5. package netscape.application;
  6.  
  7. /** Event subclass that sends the <b>performCommand()</b> message to its Target
  8.   * when processed.  To use, you must instantiate a CommandEvent, configure
  9.   * its Target, command and data, and add it to an EventLoop.
  10.   * @see Application#performCommandAndWait
  11.   * @see Application#performCommandLater
  12.   * @note 1.1 Fixed target()
  13.   */
  14. public class CommandEvent extends Event implements EventProcessor {
  15.     Target      target;
  16.     String      command;
  17.     Object      data;
  18.  
  19.     /** Constructs a CommandEvent.
  20.       */
  21.     public CommandEvent() {
  22.         super();
  23.         setProcessor(this);
  24.     }
  25.  
  26.     /** Convenience for constructing a CommandEvent. Equivalent
  27.       * to the following code:
  28.       * <pre>
  29.       *     newEvent = new CommandEvent();
  30.       *     newEvent.setTarget(target);
  31.       *     newEvent.setCommand(command);
  32.       *     newEvent.setData(data);
  33.       * </pre>
  34.       */
  35.     public CommandEvent(Target target, String command, Object data) {
  36.         this();
  37.         setTarget(target);
  38.         setCommand(command);
  39.         setData(data);
  40.     }
  41.  
  42.     /** Sets the CommandEvent's Target.
  43.       */
  44.     public void setTarget(Target target) {
  45.         this.target = target;
  46.     }
  47.  
  48.     /** Returns the CommandEvent's Target.
  49.       * @see #setTarget
  50.       */
  51.     public Target target() {
  52.         return target;
  53.     }
  54.  
  55.     /** Sets the CommandEvent's command.
  56.       */
  57.     public void setCommand(String command) {
  58.         this.command = command;
  59.     }
  60.  
  61.     /** Returns the CommandEvent's command.
  62.       * @see #setCommand
  63.       */
  64.     public String command() {
  65.         return command;
  66.     }
  67.  
  68.     /** Sets the CommandEvent's data object, the object sent in the
  69.       * <b>performCommand()</b> message to its Target.
  70.       * @see #setTarget
  71.       */
  72.     public void setData(Object data) {
  73.         this.data = data;
  74.     }
  75.  
  76.     /** Returns the CommandEvent's data object.
  77.       * @see #setData
  78.       */
  79.     public Object data() {
  80.         return data;
  81.     }
  82.  
  83.     /** Called by an EventLoop to process the CommandEvent, which results in
  84.       * the CommandEvent sending its Target the <b>performCommand()</b>
  85.       * message. You should never call this method.
  86.       */
  87.     public void processEvent(Event event) {
  88.         if (target != null) {
  89.             target.performCommand(command, data);
  90.         }
  91.     }
  92. }
  93.